---
title: OpenAI Agents SDK TypeScript
description: The OpenAI Agents SDK for TypeScript enables you to build agentic AI apps in a lightweight, easy-to-use package with very few abstractions.
---

import { LinkCard } from '@astrojs/starlight/components';
import { Code } from '@astrojs/starlight/components';
import Hero from '../../components/Hero.astro';

import helloWorldExample from '../../../../examples/docs/hello-world.ts?raw';

<Hero>
  <Fragment slot="title">Quickstart</Fragment>
  <Fragment slot="description">Build your first agent in minutes.</Fragment>
  <Fragment slot="cta">Let's build</Fragment>
</Hero>

## Overview

The [OpenAI Agents SDK for TypeScript](https://github.com/openai/openai-agents-js)
enables you to build agentic AI apps in a lightweight, easy-to-use package with
very few abstractions. It's a production-ready upgrade of our previous
experimentation for agents,
[Swarm](https://github.com/openai/swarm/tree/main), that's also [available in Python](https://github.com/openai/openai-agents-python). The Agents SDK has a very
small set of primitives:

- **Agents**, which are LLMs equipped with instructions and tools
- **Handoffs**, which allow agents to delegate to other agents for specific
  tasks
- **Guardrails**, which enable the inputs to agents to be validated

In combination with TypeScript, these primitives are powerful enough to express
complex relationships between tools and agents, and allow you to build
real-world applications without a steep learning curve. In addition, the SDK
comes with built-in **tracing** that lets you visualize and debug your agentic
flows, as well as evaluate them and even fine-tune models for your application.

## Why use the Agents SDK

The SDK has two driving design principles:

1. Enough features to be worth using, but few enough primitives to make it quick
   to learn.
2. Works great out of the box, but you can customize exactly what happens.

Here are the main features of the SDK:

- **Agent loop**: Built-in agent loop that handles calling tools, sending results to
  the LLM, and looping until the LLM is done.
- **TypeScript-first**: Use built-in language features to orchestrate and chain
  agents, rather than needing to learn new abstractions.
- **Handoffs**: A powerful feature to coordinate and delegate between multiple
  agents.
- **Guardrails**: Run input validations and checks in parallel to your agents,
  breaking early if the checks fail.
- **Function tools**: Turn any TypeScript function into a tool, with automatic
  schema generation and Zod-powered validation.
- **Tracing**: Built-in tracing that lets you visualize, debug and monitor your
  workflows, as well as use the OpenAI suite of evaluation, fine-tuning and
  distillation tools.
- **Realtime Agents**: Build powerful voice agents including automatic interruption
  detection, context management, guardrails, and more.

## Installation

```bash
npm install @openai/agents zod@3
```

## Hello world example

<Code lang="typescript" code={helloWorldExample} title="Hello World" />

(_If running this, ensure you set the `OPENAI_API_KEY` environment variable_)

```bash
export OPENAI_API_KEY=sk-...
```
